/**
 * @Author：ming
 * @Date：2023/9/26 8:00 PM
 * @Filename：Lc67
 */

/**
 * @author ming
 */
public class Lc67 {
    public String addBinary(String a, String b) {
        StringBuilder sb = new StringBuilder();
        int i =a.length()-1;
        int j = b.length()-1;
        int res = 0;

        while (i>=0||j>=0){
            char x = i>=0?a.charAt(i):'0';
            char y = j>=0?b.charAt(j):'0';

            int temp  = x-48+y-48+res;
            int now = temp%2;
            sb.append(now);
            res = temp/2;
            i--;
            j--;
        }
        if(res!=0){
            sb.append(res);
        }
        String s = sb.reverse().toString();
        return s;
    }
}
